<html>
	<head>
		<title>
			格式化工具
		</title>
	</head>
	<!--格式化工具-->
	<script src="js/base.js">
	</script>
	<script src="js/htmlformat.js">
	</script>
	<script src="js/jsformat.js">
	</script>
	<script>
		//html和js格式化方法
		function do_js_fromat() {
			//格式化内容
			js_source = document.getElementById('content').value.replace(/^\s+/, '');
			tabsize = 4;
			tabchar = ' ';
			if (tabsize == 1) {
				tabchar = '\t';
			}
			//如果以 “<” 开头就是 HTML格式化  
			if (js_source && js_source.charAt(0) === '<') {
				document.getElementById('content').value = style_html(js_source, tabsize, tabchar, 80);
			} else {
				//js 格式化
				document.getElementById('content').value = js_beautify(js_source, tabsize, tabchar);
			}
		}
		//加密方法
		function pack_js(base64) {
			var input = document.getElementById('content').value.replace(/^\s+|\s+$/g, "");
			if (input == '') {
				alert('请输入需要压缩的内容!');
				return;
			}

			var packer = new Packer;
			if (base64) {
				//加密压缩
				var output = packer.pack(input, 1, 0);
			} else {
				//普通压缩  清除格式
				var output = packer.pack(input, 0, 0);
			}
			document.getElementById('content').value = output;
        } 
        //解密
		function js_decode() {
            var input = document.getElementById('content').value.replace(/^\s+|\s+$/g, "");  
            if (input == '') {
				alert('请输入需要压缩的内容!');
				return;
            }
            var output = eval(input.slice(4)); 
			document.getElementById('content').value = output;
			do_js_fromat();
		}
	</script>
	<body>
		<textarea style="width:1000px;height:600px;" id="content">
		</textarea>
		<button onclick="do_js_fromat()">
			格式化
		</button>
		<button onclick="pack_js()">
			压缩格式
		</button>
		<button onclick="pack_js(1)">
			加密压缩
		</button>
		<button onclick="js_decode()">
			解密
		</button>
	</body>

</html>